package net.orange.framework.validator;

import net.orange.architecture.validator.IObjectValidator;
import net.orange.framework.model.Menu;

/**
 * Validation : Menu's parent can't be himself.
 */
public class MenuParentValidator extends FrameworkValidator implements
		IObjectValidator {
	/**
	 * The target menu.
	 */
	private Menu menu;

	/**
	 * Disabled the default contractor.
	 * 
	 * @exception
	 */
	@SuppressWarnings("unused")
	private MenuParentValidator() throws Exception {

	}

	/**
	 * Constructor with group object to initialize the validation.
	 * 
	 * @param menu
	 *            The target menu.
	 * @exception
	 */
	public MenuParentValidator(Menu menu) throws Exception {
		this.menu = menu;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#check()
	 */
	@Override
	public boolean check() throws Exception {
		return (menu.getParent() == null || menu.getParent().getPk() != menu
				.getPk());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#getMessage()
	 */
	@Override
	public String getMessage() {
		return message.get("error2_menu_05");
	}

}
